package com.atguigu.day11.exer.e4;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/12 16:52
 * @注释 三角形的面积和周长计算
 */
public class Triangle extends Graphic {
    private double a, b, c;

    /**
     * 重写三角形的面积
     * @return
     */
    @Override
    public double area() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }

    /**
     * 三角形的周长
     * @return
     */
    @Override
    public double perimeter() {
        return a + b + c;
    }

    /**
     * 将三角形的详细信息进行返回
     * @return
     */
    @Override
    public String toString() {
        return "边长：" + a + "," + b + "," + c + super.toString();
    }

    public Triangle(double a, double b, double c) {
        if (a > 0 && b > 0 && c > 0 && a + b > c && b + c > a && a + c > b) {
            this.a = a;
            this.b = b;
            this.c = c;
        } else {
            System.out.println("边长输入错误，无法组成三角形");
        }
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }
}
